<template>
  <div class='container' >
    <el-tabs v-model="activeName"  :stretch="true"   @tab-click="handleClick">
      <el-tab-pane :label="config.name" :name="index + ''" v-for="(config,index) in reportConfigArr" :key="index">
        <Report class="myreport" v-if="isShow(index)" :ref="index + ''" :id="index + ''" :propReportKey="config.code" style="width: 100%"></Report>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
/* eslint-disable */
  import Report from '@/components/report/Report.vue'

export default {
  name: 'reportMore',
  props: {
    propParameter: {
      type: [String],
      default: () => null
    }
  },
  data() {
    return {
      name: 'reportMore',
      activeName: '0',
      reportCodeArr: [],
      reportConfigArr: [],
      initIndexArr: []
    }
  },
  components: {
    Report
  },
  methods: {

    //查询报表列表
    getReportList() {
      let wrapper = this.$newWrapper().in('code',this.reportCodeArr )
      const params = {
        queryString: utilVue.json2str(wrapper.queryConditions),
        orderString: null
      }
      this.$ajax.get('report/config/list', {params}).then(resp => {
        if (resp.code == 0 )  this.reportConfigArr = resp.data
      })
    },

    handleClick(tab, event) {
      setTimeout(() => {
        // this.$refs[this.activeName][0].resize()
      }, 500)

    },
    isShow(indexThis){
      if (this.initIndexArr.includes(indexThis)) {
        //某种情况下列宽显示异常，此处重新计算列宽
        setTimeout(() => {
          this.$refs[this.activeName][0].$refs.grid1.recalculate(true)
        }, 500)
        return true
      }
      if (this.activeName == indexThis) {
        this.initIndexArr.push(indexThis)
        return true
      }
      return false
    },
    //刷新当前活动的报表
    fetchDataCurr(){
      this.$refs[this.activeName][0].handleQueryClick()
    }

  },
  mounted() {
    if (!this.propParameter) {
      alert('缺少参数【propParameter】')
      return
    }

    //解析 propParameter 参数
    var params = {};
    var arr = this.propParameter.split("&");
    for (var i = 0, l = arr.length; i < l; i++) {
      var a = arr[i].split("=");
      params[a[0]] = a[1];
    }
    if (params.code) {
      this.reportCodeArr = params.code.split(',')
      this.getReportList()
    }
  }
}
</script>

<style lang='scss' scoped>
  .container{
    max-height: 100%;
    overflow: auto;
    /*覆盖报表样式*/
    /deep/ .myreport{
      .title{
        display: none;
      }
    }
  }
</style>
